<%@page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="s"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="sf"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<style type="text/css">
<%@include file="../stylesheets/progresbar.css"%>
 <%@ include file="../stylesheets/main.css"%> 
<%@ include file="../stylesheets/header.css"%>
<%@ include file="../stylesheets/footer.css"%>
 <%@ include file="../stylesheets/indexContent.css"%>
<%@ include file="../stylesheets/carousel.css"%> 
</style>
<script language="JavaScript">

	function remove(id) {
		document.forms['ingRemove'].operation.value = 'ingRemove';
		document.forms['ingRemove'].selectedId.value = id;
		document.forms['ingRemove'].submit();
		return false;
	}
	function orders(id) {
		var am = prompt('Podaj Liczbę do zamówienia', '200');
		 if(am==""){
			 alert('Nieprawidłowa wartość');
			 return false;
		 }
		 if (am){
			 document.forms['order'].amount.value = am;
		document.forms['order'].operation.value = 'order';
		document.forms['order'].selectedId.value = id;
		document.forms['order'].submit();
		}
		return false;
	}
</script>
<title>Produkty</title>
</head>

<body>
	<div id="left-column-outer">
		<div id="left-column"></div>
	</div>
	<div id="center-column">
		<div class="CenteredContainer">
			<img id="background_noresize" alt="background_noresize"
				src="<%=request.getContextPath()%>/img/background.jpg" />
			<%@ include file="header.jsp"%>
			<div class="ContentShade">
			
			<div style="height:300px; overflow:auto">
				<table align="center">
					<tr>
						<th>Id </th>
						<th>Nazwa</th>
						<th>Liczba</th>
					</tr>

					<c:forEach items="${ingredientList}" var="p"
						varStatus="loop">
						<tr align="center">
						<td>${p.ingredientId }</td>
						<td>${p.name }</td>
						<td>${p.amount }</td>
						</form>
								<td align="left"><form name="ingRemove" action="ingredients"
									method="post">
									<INPUT TYPE="BUTTON" value="Usuń"
										ONCLICK="remove(${p.id})"> 
										<input type="hidden" name="operation"> 
										<input type="hidden" name="selectedId">
								</form></td>
								</form>
								<td align="left"><form name="order" action="ingredients"
									method="post">
									<INPUT TYPE="BUTTON" value="Zamów"
										ONCLICK="orders(${p.id})"> 
										<input type="hidden" name="amount"> 
										<input type="hidden" name="operation"> 
										<input type="hidden" name="selectedId">
								</form></td>
						
						</tr>
					</c:forEach><tr>
	</tr>
					
				</table>
</div>
<sf:form method="POST" action="ingredients" commandName="ingredient">
						<tr><td></td>
							<td><sf:input path="name" /></td>
							<td></td>
							<td colspan="2"><input type="submit" value="Dodaj składnik"></td>
						
						</tr>
				</sf:form>
				<%@ include file="footer.jsp"%>
			</div>
		</div>
	</div>
	<div id="right-column-outer">
		<div id="right-column"></div>
	</div>

</body>